<template>
	<view class="home">
		<swiper :indicator-dots="true" circular :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.url"></image>
			</swiper-item>

		</swiper>
		<!--导航区域-->
		<view class="nav">
			<view class="nav_item" v-for="(item,index) in navs" :key="index" @click="navItemClick(item.path)">
				<view  :class = "item.icon"></view>
				<text>{{item.title}}</text>
			</view>
			
		</view>
		<!-- 推荐商品 -->
		<view class="hot_goods">
			<view class="tit">推荐</view>
			<goods-list :goods="goods"></goods-list>

		</view>
	</view>
</template>

<script>
	import goodsList from '../../components/goods-list/goods-list.vue'
	export default {
		data() {
			return {
				title: 'Hello',
				swipers: [],
				goods:[],
				navs:[{
					icon:'iconfont icon-ziyuan',
					title:'银龙超市',
					path:'/pages/goods/goods'
				},
				{
					icon:'iconfont icon-tupian',
					title:'爱代码',
					path:'/pages/pics/pics'
				},
				{
					icon:'iconfont icon-shipin',
					title:'爱理财',
					path:'/pages/fund/fund'
				},
				{
					icon:'iconfont icon-guanyuwomen',
					title:'联系我们',
					path:'/pages/contact/contact'
				}
				]
			}
		},
		onLoad() {
			this.getSwipers()
			this.getHotGoods()
		},
		components:{
			"goods-list":goodsList
		},
		methods: {
			//获取轮播图的数据
			getSwipers() {
				console.log("获取轮播")
				// uni.request({
				// 	url:"https://www.baidu.com/",
				// 	success:res=>{
				// 	console.log("添加数组")
				// 	this.swipers.push("static/lunbo/bg1.jpg");
				// 	this.swipers.push("static/lunbo/hx1.jpg");
				// 	this.swipers.push("static/lunbo/hx2.jpg");
				// },
				// })
				this.$myRequest({
					url: 'https://www.baidu.com',
				})
				this.swipers.push({
					id: 0,
					url: "../../static/lunbo/bg1.jpg"
				});
				this.swipers.push({
					id: 1,
					url: "../../static/lunbo/hx1.jpg"
				});
				this.swipers.push({
					id: 2,
					url: "../../static/lunbo/hx2.jpg"
				});
			},
			//获取热门商品列表
			//https://demoapi.dtcms.net/upload/202104/15/09571005-43a9-49c2-ad27-a2754363c7fb.jpg
			getHotGoods(){
				for (var i=0;i<10;i++){
					this.goods.push({
						id: i,
						img_url: "https://demoapi.dtcms.net/upload/202104/15/09571005-43a9-49c2-ad27-a2754363c7fb.jpg",
						sell_price:10000,
						market_price:30000,
						title:'爱代码,爱理财,爱QQ'
					});
				}
				console.log(this.goods.length)
			},
			navItemClick(path){
				console.log("跳转")
				console.log(path)
				uni.navigateTo({
					url:path
				})
			}
			
			
		}
	}
</script>

<style lang="scss">
	.home {
		swiper {
			width: 750rpx;
			height: 380rpx;

			image {
				height: 100%;
				width: 100%;
			}

		}

		.nav {
			display: flex;

			.nav_item {
				width: 25%;
				text-align: center;

				view {
					width: 120rpx;
					height: 120rpx;
					background: $shop-color;
					border-radius: 60rpx;
					margin: 10px auto;
					line-height: 120rpx;
					color: #ffff;
					font-size: 50rpx;
				}

				.icon-tupian {
					font-size: 45rpx;
				}

				text {
					font-size: 30rpx;
				}
			}
		}

		.hot_goods {
			background: #eee;
			overflow: hidden;
			margin-top: 10px;

			.tit {
				height: 50px;
				line-height: 50px;
				color: $shop-color;
				text-align: center;
				letter-spacing: 20px;
				background: #fff;
				margin: 7rpx 0;
			}


		}
	}
</style>
